package com.elinkway.infinitemovies.http.requesttask;

import android.content.Context;

import com.elinkway.infinitemovies.async.MoviesHttpAsyncTask;
import com.elinkway.infinitemovies.async.RequestResultListener;
import com.elinkway.infinitemovies.bean.ReportSubmitBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.ReportSubmitParser;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Created by zhaopeipei on 2016/6/15.
 */
public class UploadUserFeedbackTask  extends MoviesHttpAsyncTask<ReportSubmitBean> {

    private static final String TAG = "UploadUserFeedbackTask";

    private RequestResultListener <ReportSubmitBean> mListener;

    private Context mContext;

    private String mScope;

    private String mAid;

    private String mDescription;


    @Override
    public void netNull() {
        super.netNull();
        if(null != mListener) {
            mListener.onRequestFailed();
        }
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        super.netErr(updateId, errMsg);
        if(null != mListener) {
            mListener.onRequestFailed();
        }
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        super.dataNull(updateId, errMsg);
        if(null != mListener) {
            mListener.onRequestFailed();
        }
    }

    public UploadUserFeedbackTask(Context context, String scope, String aid, String description) {
        super(context);
        mContext = context;
        mScope = scope;
        mAid = aid;
        mDescription = description;
    }

    @Override
    public LVideoDataHull<ReportSubmitBean> doInBackground() {
        LVideoDataHull<ReportSubmitBean> ret = MoviesHttpApi.postUserFeedback(
                new ReportSubmitParser(), mScope, mAid, mDescription);
        if (ret.getDataType() == LVideoDataHull.DataType.DATA_IS_INTEGRITY) {
            ReportSubmitBean v = ret.getDataEntity();
        }
        return ret;
    }

    @Override
    public void onPostExecute(int updateId, ReportSubmitBean result) {
        if(null != mListener) {
            mListener.onRequestSuccess(updateId, result);
        }
    }

    public void setListener(RequestResultListener<ReportSubmitBean> mListener) {
        this.mListener = mListener;
    }


}
